package IO.File;

import org.junit.Test;

import java.io.File;
import java.io.FilenameFilter;
import java.io.IOException;
import java.util.Arrays;
import java.util.stream.Stream;

public class FileTest {
    @Test
    public void testFilePath(){
        System.out.println("C:\\Windows\\System32\\drivers\\etc");
    }
    @Test
    public void testCreatFile(){
        File file = new File("G:\\壁纸");
        File parent = new File("G:\\壁纸","1.jpg");
        File file3 = new File(parent,"1.jpg");
    }
    @Test
    public void testFile() throws IOException {
        File file = new File("G:\\壁纸\\1.txt");
        System.out.println("file.getName() = " + file.getName());
        System.out.println("file.getUsableSpace() = " + file.getUsableSpace());
//        System.out.println("file.delete() = " + file.delete());
        System.out.println("file.mkdirs() = " + file.exists());
        if(file.exists()){
//            System.out.println("file.createNewFile() = " + file.createNewFile());
            System.out.println("file.delete() = " + file.delete());
        }
        System.out.println("file.canRead() = " + file.canRead());
        System.out.println("file.getParent() = " + file.getParent());
        System.out.println("file.lastModified() = " + file.lastModified());
        System.out.println("file.renameTo(new File(\"G:\\\\壁纸\",\"3.jpg\")) = " + file.renameTo(new File("G:\\壁纸", "3.jpg")));
    }
    @Test
    public void testFindAllPng(){
       FileTest fileTest = new FileTest();
       fileTest.FindAll("E:\\壁纸");

    }
    @Test
    public void FindAll(String path){
        //尝试列出当前文件夹下所有的文件
        File file = new File(path);
        //过滤文件和文件夹
        File[] list = file.listFiles(( (dir, name) -> new File(dir,name).isDirectory()||name.contains("jpg")));
        if(list == null||list.length==0){
            return;
        }
        for (File parent : list) {
            //看看是不是文件夹.如果是
            if(parent.isDirectory()){
                FindAll(parent.getAbsolutePath());

            }else {
                System.out.println(parent.getName());
            }
        }
//        System.out.println(Arrays.toString(list));
    }


}

